package org.agony2d.gpu {
	import flash.display.BitmapData;
	import flash.geom.Rectangle;
	import org.agony2d.gpu.core.AAManager;
	import org.agony2d.gpu.core.animation.SheetAA;
	import org.agony2d.gpu.core.AnimatorAA;
	import org.agony2d.gpu.core.WorldAA;
	import org.agony2d.gpu.supportClasses.textures.TextureManager;
	import org.agony2d.core.agony_internal;
	import org.agony2d.core.UpdaterManager;
	import org.agony2d.debug.Logger;
	
	use namespace agony_internal;
	
	[Event(name = "beginning", type = "org.agony2d.notify.AEvent")]
	
	[Event(name = "reset",     type = "org.agony2d.notify.AEvent")] 
	
	/** [ AAFacade ]...(Agony Accelerated App)
	 *  [◆]
	 *  	1.  enableErrorChecking
	 *  	2.  paused
	 *  	3.  animatorSpeedRatio
	 *  [◆◆]
	 *  	1.  startup
	 * 
	 *  	2.  addFullTexture
	 *  	3.  addAtlas
	 *  	4.  addRegionTexture
	 *  	5.  killTextures
	 * tuh
	 *  	6.  createWorld
	 *  	7.  getWorldAt
	 *  [★]
	 *  	a.  2d平台型
	 *  	b.  2d纵版射击
	 *  	c.  2d解谜益智
	 *  	d.  2d-ARPGd
	 */
public class AAFacade {
	
	public static function get enableErrorChecking() : Boolean {	
		return AAManager.g_enableErrorChecking
	}
	
	public static function set enableErrorChecking( b:Boolean ) : void {
		AAManager.enableErrorChecking = b
	}
	
	public static function get paused() : Boolean {
		return AAManager.g_paused
	}
	
	public static function set paused( b:Boolean ) : void {
		if (AAManager.g_paused != b) {
			AAManager.g_paused = b
			Logger.reportMessage("AA", (b ? '▼' : '▲') + ' paused [ ' + b + ' ]...')
		}
	}
	
	public static function get animatorSpeedRatio() : Number {
		return AnimatorAA.g_globalSpeedRatio
	}
	
	public static function set animatorSpeedRatio( v:Number ) : void {
		AnimatorAA.g_globalSpeedRatio = (v < 0 || isNaN(v)) ? 0 : v
	}
	
	public static function startup( bgColor:uint,
									hasMaskForAspectRatio:Boolean = false,
									antiAlias:int = 0,
									profile:String = "baselineConstrained", 
									stage3dIndex:int = 0 ) : void {
		AAManager.g_stage = UpdaterManager.g_stage
		g_AA.startup(bgColor, hasMaskForAspectRatio, antiAlias, profile, stage3dIndex)
	}
	
	public static function addFullTexture( name:String, BA:BitmapData, mipmapEnabled:Boolean = false ) : void {
		TextureManager.addFullTexture(name, BA, mipmapEnabled)
	}
	
	public static function addAtlas( fullTexName:String, atlasXml:XML ) : void {
		TextureManager.addAtlas(fullTexName, atlasXml)
	}
	
	public static function addRegionTexture( fullTexName:String, name:String, region:Rectangle ) : void {
		TextureManager.addRegionTexture(fullTexName, name, region)
	}
	
	public static function killTextures( ...texNames ) : void {
		TextureManager.killTextures(texNames)
	}
	
	public static function createWorld( width:int = -1, height:int = -1, invalidWhenLeave:Boolean = false, worldName:String = null ) : WorldAA {
		return g_AA.createWorld(width, height, invalidWhenLeave)
	}
	
	public static function getWorldAt( index:int ) : WorldAA {
		return g_AA.getWorldAt(index)
	}
	
	public static function addSheet( sheetName:String, totalFrames ) : SheetAA {
		return SheetAA.addSheet(sheetName, totalFrames)
	}
	
	public static function addSheetsByXml( sheetXml:XML ) : void {
		SheetAA.addSheetsByXML(sheetXml)
	}
	
	public static function getSheet( sheetName:String ) : SheetAA {
		return SheetAA.m_sheetMap[sheetName]
	}
	
	public static function addEventListener( type:String, listener:Function, priority:int = 0 ) : void {
		g_AA.addEventListener(type, listener, priority)
	}
	
	public static function removeEventListener( type:String, listener:Function ) : void {
		g_AA.removeEventListener(type, listener)
	}
	
	
	private static var g_AA:AAManager = new AAManager
}
}